package com.photographysharing.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.photographysharing.dto.CommentDTO;
import com.photographysharing.entity.Comments;
import com.photographysharing.request.SelectByPaging;
import com.photographysharing.response.DatasResponse;
import com.photographysharing.service.CommentsService;
import com.photographysharing.mapper.CommentsMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Z
* @description 针对表【comments】的数据库操作Service实现
* @createDate 2024-05-14 21:15:11
*/
@Service
public class CommentsServiceImpl extends ServiceImpl<CommentsMapper, Comments>
    implements CommentsService{

    private CommentsMapper commentsMapper;

    public CommentsServiceImpl(CommentsMapper commentsMapper) {
        this.commentsMapper = commentsMapper;
    }

    @Override
    public boolean comment(Comments comment) {
        //评论入库
        if(this.save(comment)){
            //添加私信

            return true;
        }
        return false;
    }

    @Override
    public DatasResponse<CommentDTO> getComments(@Param("photoId") String photoId) {
         List<CommentDTO> datas =  commentsMapper.getComments(photoId);

        return new DatasResponse<CommentDTO>(datas.size(),datas);
    }

    @Override
    public DatasResponse<CommentDTO> selectByPag(SelectByPaging pag) {
        int index = pag.getIndex();
        int size = pag.getSize();
        String name = pag.getSearchName();
        String userName = pag.getSearchValue1();
        List<CommentDTO> datas= commentsMapper.selectByPag((index-1)*size,size,name,userName);
        int count =commentsMapper.selectByPagCount(name,userName);
        return new DatasResponse<>(count,datas);
    }
}




